#include "paintshadow.h"

#include <QPainterPath>

PaintShadow::PaintShadow(QPaintDevice * paintDevice, int shadow_width, int radius) {
    QPainter painter(paintDevice);
    // 绘制立体阴影边框效果
    painter.setPen(Qt::NoPen);  // 不显示边框
    painter.setRenderHint(QPainter::Antialiasing, true);    // 开启抗锯齿
    QColor color(50, 50, 50, 30);   // 透明的灰色
    for (int i = 0; i < shadow_width; i++)
    {
        color.setAlpha(40 - (i * 5));
        painter.setPen(color);
        // 绘制圆角阴影边框(从内到外逐渐变透明)
        int beginXY = shadow_width - i; // 起始相对位置（xy一样就用一个变量了）
        int width = paintDevice->width() - (shadow_width - i) * 2;  // 整体宽度减去两边
        int height = paintDevice->height() - (shadow_width - i) * 2;    // 整体高度减去上下
        painter.drawRoundedRect(beginXY, beginXY, width, height, radius, radius);
    }

}
